package com.immortal.core.utils;

import com.google.common.util.concurrent.*;

import javax.annotation.Nullable;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;

public class ThreadUtil {
    private static ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2));

    public static void submit(Callable callable, FutureCallback futureCallback){
        ListenableFuture<Object> submit = executorService.submit(callable);
        Futures.addCallback(submit, futureCallback);
    }
    public static void submit(Callable callable){
        ListenableFuture<Object> submit = executorService.submit(callable);
        Futures.addCallback(submit, new FutureCallback<Object>() {
            @Override
            public void onFailure(Throwable throwable) {
            }

            @Override
            public void onSuccess(@Nullable Object o) {

            }
        });
    }
    public static  void shutdown(){
        executorService.shutdown();
    }
}
